Coder Social home page Coder Social logo

Comments (3)

mivade avatar mivade commented on May 14, 2024 1

See lovasoa/marshmallow_dataclass#186 for a solution to a similar problem.

Personally I never do this import because it has caused problems in the past with other libraries but I would be willing to accept a PR that addresses this.

from argparse_dataclass.

ymd-h avatar ymd-h commented on May 14, 2024

I encountered the same issue.
By patching argparse_dataclass.fields() based on @isbadawi's idea, I could solve the error.

from __future__ import annotations
from dataclasses import fields
import argparse_dataclass
from typing import get_type_hints

def _patch_fields(cls, *args, **kwargs):
    t = get_type_hints(cls)
    def _update(_f):
        _f.type = t[_f.name]
        return _f
    
    return tuple(_update(f) for f in fields(cls, *args, **kwargs))

argparse_dataclass.fields = _patch_fields


@argparse_dataclass.dataclass
class MyArgs:
    foo: int = 0
    bar: str = 'hello'
    baz: bool = False

def main():
    print(MyArgs.parse_args())

if __name__ == '__main__':
    main()
MyArgs(foo=0, bar='hello', baz=False)

from argparse_dataclass.

ymd-h avatar ymd-h commented on May 14, 2024

@mivade
Thank you for your reply.

I sent PR (#51).

from argparse_dataclass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.