Skip to content

Class-qualified annotation expressions #1884

Open
@samwgoldman

Description

@samwgoldman

The wonderfully useful specification of type annotation expressions describes what kinds of expressions are valid type annotations.

I believe the spec does not include a case which type checkers support, although as we will see this comes down to semantics :)

class A:
    class B:
        pass

x: A.B = A.B()

The A.B annotation seems to fall under the name rule:

| name
      (where name must refer to a valid in-scope class,
       type alias, or TypeVar)

The spec helpfully continues:

Any leaf denoted as name may also be a qualified name (i.e., module '.' name or package '.' module '.' name, with any level of nesting).

The concept of a "qualified name" occurs only in this section, and the parenthetical explanation serves as it's most precise definition, as far as I can tell.

Should we extend the definition of "qualified name" to also include class members? Or maybe I should read the class as a "module" or a "package" and the existing definition suffices?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions