Skip to content

Questions about scoping rules and PEP 563 #4726

@tristanlatr

Description

@tristanlatr

Describe the current behaviour
Whether we use from __future__ import annotations or not radically changes the scoping rules. I suppose this is designed this way. But pyright is not in agreement with mypy on this particular topic.

To Reproduce

This typechecks correctly with pyright (but mypy complains about F being not a valid type). I'm not saying it shouldn't, just saying it looks like there are some discrepancies in how mypy and pyright handle this specific (and totally theoretical) case.

from __future__ import annotations
class C:
  F = b'not a valid type'
  def f(self) -> F:
    return F()

class F:
  ...

Expected behavior
I'd expect pyright to have the same behaviour as mypy (or the other way around, I don't care). From the perspective of a developer of static analysis tools, I don't know which behaviour is the "right way". I've read about all the typing PEPs and couldn't find a clear and definitive answer.

Thanks

PS, this is not a bug report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions