Skip to content

Fix type of forward reference to a decorated class method #4486

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

Merged
merged 4 commits into from
Feb 19, 2018

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 18, 2018

The decorator case wasn't properly handled before when accessing an attribute
through a type object -- the type of the forward reference defaulted to Any.

The fix doesn't work at module top level since module top levels can't
be deferred, but the reference would generally fail at runtime anyway.

Fixes #4485.

The case wasn't properly handled before when accessing through a type
object -- the type of the forward reference defaulted to `Any`.

The fix doesn't work at module top level since module top levels can't
be deferred, but the reference would generally fail at runtime anyway.

Fixes #4485.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 25, 2018

This is now ready for review. I've addressed the issues in Dropbox internal code.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two optional comments.

@classmethod
def h(cls) -> None:
reveal_type(cls.g) # E: Revealed type is 'def (x: builtins.str)'
[builtins fixtures/classmethod.pyi]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add reveal_type(A.g) after the class definition here?

return node.node.type
else:
not_ready_callback(name, context)
return AnyType(TypeOfAny.special_form)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that we normally return TypeOfAny.from_error in all cases where the may be an error.

@JukkaL JukkaL merged commit 3545a71 into master Feb 19, 2018
@gvanrossum gvanrossum deleted the classmethod-forwardref branch February 21, 2018 16:16
carljm added a commit to carljm/mypy that referenced this pull request Feb 28, 2018
* master: (27 commits)
  Don't call --strict-optional and --incremental experimental (python#4642)
  Sync typeshed (python#4641)
  Fix callable types with inconsistent argument counts (python#4611)
  Fix example (add 'class A:')
  Make psutil an optional dependency (python#4634)
  mypy and mypy_extensions aren't posix only (python#3765)
  Documentation for attr support (python#4632)
  Use read_with_python_encoding in stubgen to handle file encoding (python#3790)
  Sync typeshed (python#4631)
  Add remaining core team emails to CREDITS (python#4629)
  Fix issues with attr code. (python#4628)
  Better support for converter in attrs plugin. (python#4607)
  Clean up credits (python#4626)
  Support type aliases in fine-grained incremental mode (python#4525)
  Fine-grained: Fix crash caused by unreachable class (python#4613)
  Treat divmod like a binary operator (python#4585)
  Sync typeshed (python#4605)
  Fine-grained: Don't infer partial types from multiple targets (python#4553)
  Fine-grained: Compare symbol table snapshots when following dependencies (python#4598)
  Fix type of forward reference to a decorated class method (python#4486)
  ...
yedpodtrzitko pushed a commit to kiwicom/mypy that referenced this pull request Mar 15, 2018
The case wasn't properly handled before when accessing through a type
object -- the type of the forward reference defaulted to `Any`.

The fix doesn't work at module top level since module top levels can't
be deferred, but the reference would generally fail at runtime anyway.

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

Successfully merging this pull request may close these issues.

Forward reference to decorated class method has type Any
2 participants