diff options
author | David Beazley <dave@dabeaz.com> | 2017-12-02 13:43:18 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-02 13:43:18 -0600 |
commit | 1f9775de4af64dde4a81313e1c022381161d5b7f (patch) | |
tree | 640c27425929ddb6146b57d88e9f8458b01eb816 /ply/yacc.py | |
parent | e5925a4d0f0a3a9b9459313403fda09b04bfd9cf (diff) | |
parent | ebf2d286d5dfc4cd255d523366f067df6ee48d14 (diff) | |
download | ply-1f9775de4af64dde4a81313e1c022381161d5b7f.tar.gz |
Merge pull request #141 from segevfiner/fix-tabmodule-class-in-package
Calculate the correct tabmodule for parsers defined in a class inside a package
Diffstat (limited to 'ply/yacc.py')
-rw-r--r-- | ply/yacc.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ply/yacc.py b/ply/yacc.py index 23f4c24..ceaaefd 100644 --- a/ply/yacc.py +++ b/ply/yacc.py @@ -3231,9 +3231,13 @@ def yacc(method='LALR', debug=yaccdebug, module=None, tabmodule=tab_module, star if module: _items = [(k, getattr(module, k)) for k in dir(module)] pdict = dict(_items) - # If no __file__ attribute is available, try to obtain it from the __module__ instead + # If no __file__ or __package__ attributes are available, try to obtain them + # from the __module__ instead if '__file__' not in pdict: pdict['__file__'] = sys.modules[pdict['__module__']].__file__ + if '__package__' not in pdict and '__module__' in pdict: + if hasattr(sys.modules[pdict['__module__']], '__package__'): + pdict['__package__'] = sys.modules[pdict['__module__']].__package__ else: pdict = get_caller_module_dict(2) |