Skip to content
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

@check of _init__ fails #466

Closed
martinwk opened this issue Nov 23, 2016 · 3 comments
Closed

@check of _init__ fails #466

martinwk opened this issue Nov 23, 2016 · 3 comments
Labels

Comments

@martinwk
Copy link

Say I have this class:

class SomeClass
    @ureg.check(None, None,
                '[length] ** 2 / [time]',
                )
    def __init__(self, name='test',
                 D_s=2.4e-15 * ureg('m ** 2 / s'),
                       ):

        print D_s
        self.name  = name

    @ureg.check(None, None, None, '=A/A')  # this is a hack for dimensionless
    def testFunc(self, name='aaa',
                 Kf=300. * ureg('(g/g_substrate)*(L/g) ** 0.3'),
                 n_inv=0.3 * ureg.dimensionless):
         print self
         print name
         print Kf
         print n_inv

when I create some instance of the class,

some_instance = SomeClass()

it fails with the error:

  File "C:\Users\korevma\AppData\Local\Continuum\Anaconda2\lib\site-packages\pint\registry_helpers.py", line 210, in wrapper
  
if dim and value.dimensionality != dim:
AttributeError: 'NoneType' object has no attribute 'dimensionality'

When I remove the check for the init() and then run the testFunc()

some_instance.testFunc()

no errors are returned. What am I doing wrong

@hgrecco
Copy link
Owner

hgrecco commented Nov 23, 2016

This works for me with master.

import pint
ureg = pint.UnitRegistry()

class SomeClass:
    @ureg.check(None, None, '[length] ** 2 / [time]')
    def __init__(self, name, D_s):
        print(name, D_s)

    @ureg.check(None, None, '[length] ** 2 / [time]')
    def test(self, name, D_s):
        print(name, D_s)

x = SomeClass('Help!', 3 * ureg.m * ureg.m / ureg.s)
x.test('Please!', 1 * ureg.m * ureg.m / ureg.s)

It might be a problem with the default values. We should fixed together with #439

@martinwk
Copy link
Author

Yes, removing default values makes it work for me too. Which solves this issue to some extent.

I would like to have the default values though. I am looking forward to your fix :)

@hgrecco hgrecco added the docs label Apr 1, 2017
@hgrecco
Copy link
Owner

hgrecco commented Dec 3, 2019

Closing. Feel free to reopen if you keep encountering this problem.

@hgrecco hgrecco closed this as completed Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants