Skip to content

Parameter converter of the field() function for @dataclass_transform #9140

Answered by erictraut
luwqz1 asked this question in Q&A
Discussion options

You must be logged in to vote

Here's what I mean when I say that the __get__ method of a descriptor object isn't invoked if the descriptor object is an instance variable.

class Desc:
    def __get__(self, instance, owner):
        return 1

class Foo:
    # Assign a descriptor object to a class variable
    a = Desc()

    def __init__(self):
        # Assign a descriptor object to an instance variable
        self.b = Desc()

print(Foo().a)  # prints 1
print(Foo().b)  # prints Desc

What is the type of the object that your converter function returns? That's the type that should appear in the annotation for last_name attribute.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@luwqz1
Comment options

@erictraut
Comment options

Answer selected by luwqz1
@luwqz1
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants