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

Deprecation warning is incorrect #46

Open
nsheff opened this issue Mar 18, 2021 · 5 comments
Open

Deprecation warning is incorrect #46

nsheff opened this issue Mar 18, 2021 · 5 comments
Labels
bug Something isn't working likely-solved

Comments

@nsheff
Copy link
Member

nsheff commented Mar 18, 2021

In [17]: yam = yacman.YacAttMap(filepath="project_config.yaml")

In [18]: yam._file_path
/home/nsheff/.local/lib/python3.8/site-packages/yacman/yacman.py:365: UserWarning: The '_file_path' property is deprecated and will be removed in a future relase. Use YacAttMap.__internal._file_path instead.
  warn(
Out[18]: '/home/nsheff/project_config.yaml'

But:

In [19]: yam.__internal._file_path
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/attmap/_att_map_like.py in __getattr__(self, item, default)
     33         try:
---> 34             return super(AttMapLike, self).__getattribute__(item)
     35         except AttributeError:

AttributeError: 'AttMap' object has no attribute '_file_path'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/attmap/_att_map_like.py in __getattr__(self, item, default)
     36             try:
---> 37                 return self.__getitem__(item)
     38             except KeyError:

~/.local/lib/python3.8/site-packages/attmap/attmap.py in __getitem__(self, item)
     31     def __getitem__(self, item):
---> 32         return self.__dict__[item]
     33 

KeyError: '_file_path'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-19-b22463bccc3a> in <module>
----> 1 yam.__internal._file_path

~/.local/lib/python3.8/site-packages/attmap/_att_map_like.py in __getattr__(self, item, default)
     39                 # Requested item is unknown, but request was made via
     40                 # __getitem__ syntax, not attribute-access syntax.
---> 41                 raise AttributeError(item)
     42 
     43     @abc.abstractmethod

AttributeError: _file_path

And:

In [20]: yam.__internal.file_path
Out[20]: '/home/nsheff/project_config.yaml'
@nsheff
Copy link
Member Author

nsheff commented Mar 18, 2021

Related, the hanging 'warn(' in the error message is strange-looking.

@nsheff nsheff added the bug Something isn't working label Mar 18, 2021
@nsheff
Copy link
Member Author

nsheff commented Mar 18, 2021

3rd issue -- when I'm calling this from an external package (like bulker), it doesn't provide function stack trace so I can see where the offending line is coming from to fix it. It just shows the line of code in yacman to this warning , which is not helpful. It may be related to the fact that it just says "warn(" without further detail.

@nsheff
Copy link
Member Author

nsheff commented Mar 18, 2021

nsheff added a commit that referenced this issue Mar 18, 2021
@nsheff
Copy link
Member Author

nsheff commented Mar 18, 2021

Here are some ideas:

import sys 
import traceback

# Credit: https://stackoverflow.com/questions/22373927/
# def warn_with_traceback(message, category, filename, lineno, file=None, line=None):

#     log = file if hasattr(file,'write') else sys.stderr
#     traceback.print_stack(file=log)
#     log.write(warnings.formatwarning(message, category, filename, lineno, line))

# warnings.showwarning = warn_with_traceback
# def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
#         return '%s:%s: %s:%s\n' % (filename, lineno, category.__name__, message)

# warnings.formatwarning = warning_on_one_line

@nsheff
Copy link
Member Author

nsheff commented Feb 7, 2023

This will no longer be an issue in the new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working likely-solved
Projects
None yet
Development

No branches or pull requests

1 participant