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

spurious deprecation warnings #151

Open
anarcat opened this issue Oct 18, 2018 · 5 comments
Open

spurious deprecation warnings #151

anarcat opened this issue Oct 18, 2018 · 5 comments

Comments

@anarcat
Copy link

anarcat commented Oct 18, 2018

recently (since after 5.1.3) the feed2exec test suite started failing because this warning was mangling the output of the script:

/home/anarcat/src/feed2exec/.tox/py36/lib/python3.6/site-packages/feedparser.py:345: DeprecationWarning: To avoid breaking existing software while fixing issue 310, a temporary mapping has been created from `updated_parsed` to `published_parsed` if `updated_parsed` doesn't exist. This fallback will be removed in a future version of feedparser.

It's unclear to me how to disable this warning. Any access of the property will trigger the warning. I believe the should be a way to behave properly for the library consumers and disable the warning, for example by having a default value for the get parameter. I have tried that, without any luck:

--- c/feed2exec/email.py
+++ i/feed2exec/email.py
@@ -97,7 +97,7 @@ def make_message(feed, item, to_addr=None, cls=email.message.Message):
     #
     # also, default on the feed updated date
     orig = timestamp = datetime.datetime.utcnow().timestamp()
-    timestamp = item.get('updated_parsed') or orig
+    timestamp = item.get('updated_parsed', item.get('published_parsed', orig))
     if isinstance(timestamp, (datetime.datetime,
                               datetime.date,
                               datetime.time)):

I have reverted to silencing the warnings altogether, which seems suboptimal. It would be better if there was a way to comply with the deprecation warning correctly without having to disable warnings.

Thanks!

@mgedmin
Copy link

mgedmin commented Nov 3, 2018

@anarcat your code is still accessing updated_parsed even when published_parsed exists. I think you want this instead:

    timestamp = item.get('published_parsed') or orig

or, if you intend to keep feed2exec compatible with older feedparser versions that do not provide published_parsed, you could do

    timestamp = item.get('published_parsed') or item.get('updated_parsed') or orig

@anarcat
Copy link
Author

anarcat commented Nov 3, 2018

but that would prioritize published_parsed over updated_parsed which is not what i want. it would also still yield warnings if published_parsed is missing or empty.

@ikwyl6
Copy link

ikwyl6 commented Nov 12, 2019

So in general should I be using updated_parsed instead of trying to get published_parsed?

@anarcat
Copy link
Author

anarcat commented Nov 13, 2019

that is the question. the deprecation warning here should make it clearer what the proper way out is. right now it's ambiguous.

@lyz-code
Copy link

I've stumbled upon the same error today, @kurtmckee which is the official position on using updated_parsed or published_parsed?

lyz-code added a commit to lyz-code/blue-book that referenced this issue Feb 17, 2022
[Roguelynn tutorial](https://www.roguelynn.com/words/asyncio-we-did-it-wrong/)

feat(feedparser#issues): Add issue when using `updated_parser`

[Deprecation warning when using `updated_parsed`](kurtmckee/feedparser#151)

fix(pytest): update the tmpdir_factory type hints

You should now use `TempPathFactory` instead of `TempdirFactory`

fix(pytest#global-usage): Use `pytest-freezegun` globally

[Most of the tests](https://medium.com/@boxed/flaky-tests-part-3-freeze-the-world-e4929a0da00e)
work with frozen time, so it's better to freeze it by default and unfreeze it on
the ones that actually need time to move.

To do that set in your `tests/conftest.py` a globally used fixture:

```python
if TYPE_CHECKING:
    from freezegun.api import FrozenDateTimeFactory

@pytest.fixture(autouse=True)
def frozen_time() -> Generator['FrozenDateTimeFactory', None, None]:
    """Freeze all tests time"""
    with freezegun.freeze_time() as freeze:
        yield freeze
```

feat(pytest): Ignore a warning of a specific package

In the `pyproject.toml`

```toml
filterwarnings = [
  "error",
  # Until ktosiek/pytest-freezegun#35 is merged
  "ignore::DeprecationWarning:pytest_freezegun.*"
]
```

feat(python_snippets#How to raise a warning): How to raise a warning

Warning messages are typically issued in situations where it is useful to alert
the user of some condition in a program, where that condition (normally) doesn’t
warrant raising an exception and terminating the program. For example, one might
want to issue a warning when a program uses an obsolete module.

```python
import warnings

def f():
    warnings.warn('Message', DeprecationWarning)
```

To test the function with pytest you can use
[`pytest.warns`](https://docs.pytest.org/en/stable/how-to/capture-warnings.html#warns):

```python
import warnings
import pytest

def test_warning():
    with pytest.warns(UserWarning, match='my warning'):
        warnings.warn("my warning", UserWarning)
```

feat(python_snippets#Parse XML file with beautifulsoup): Parse XML file with beautifulsoup

You need both `beautifulsoup4` and `lxml`:

```python
bs = BeautifulSoup(requests.get(url), "lxml")
```

feat(python_snippets#Get a traceback from an exception): Get a traceback from an exception

```python
import traceback

traceback_str = ''.join(traceback.format_tb(e.__traceback__))
```

feat(flakeheaven): Deprecate flakehell in favour of flakeheaven

It's a fork maintained by the community, instead of an absent code
dictator.

feat(fastapi#Resolve the 307 error): Resolve the 307 error

Probably you've introduced an ending `/` to the endpoint, so instead of asking
for `/my/endpoint` you tried to do `/my/endpoint/`.

feat(pdm): Version overriding now supports constrains

Before you had to pin specific versions, which is not maintainable, now
you can use constrains

```toml
[tool.pdm.overrides]
asgiref = ">=3.2.10"
```

feat(pdm#Show outdated packages): Show outdated packages

```bash
pdm update --dry-run --unconstrained
```

fix(pydantic_factories): correct the type hints of the factory

Use `Any`

```python
class PersonFactory(ModelFactory[Any]):
    ...
```

feat(pydantic_factories#issues): Track issue when using with
`pytest-freezegun`

[Use pydantic-factories with pytest-freezegun](litestar-org/polyfactory#29)

feat(python#install): Install a specific version

* Install dependencies
    ```bash
    sudo apt install wget software-properties-common build-essential libnss3-dev zlib1g-dev libgdbm-dev libncurses5-dev libssl-dev libffi-dev libreadline-dev libsqlite3-dev libbz2-dev
    ```

* Select the version in https://www.python.org/ftp/python/ and download it
    ```bash
    wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz
    cd Python-3.9.2/
    ./configure --enable-optimizations
    sudo make altinstall
    ```

perf(regicide): fix typos

fix(wallabag): Remove Wallabag rss issue as it's solved

Rss feeds linked to the wallabag instance instead to the referenced article, not anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants