Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with annotated class constants #4266

Merged
merged 1 commit into from
Mar 30, 2021
Merged

Fix issue with annotated class constants #4266

merged 1 commit into from
Mar 30, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Mar 30, 2021

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

This MR fixes an issue introduced with #4185. The error occurs if a class var with an annotation subscript, that is an attribute, is parsed. See example below

import typing
from typing import List

import custom_path


class Custom:
    var: List[int]
    var2: typing.List[int]  # error

    var3: custom_path.MyOtherClass  # works

A workaround, until a new version is released, would be to not use attribute access for class variable annotations with subscript. Instead import the name directly, eg. from typing import List.

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes #4264

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 91.458% when pulling 4117777 on cdce8p:fix-annotated-class-constants into 245feab on PyCQA:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[2.7.3 regression] AttributeError: 'Attribute' object has no attribute 'name'
3 participants