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

[pre-commit.ci] pre-commit autoupdate #431

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.2
hooks:
- id: ruff
- id: ruff-format
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ exclude = [
"src/textblob/_text.py",
]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
Expand Down
1 change: 1 addition & 0 deletions src/textblob/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.. versionchanged:: 0.7.0
All base classes are defined in the same module, ``textblob.base``.
"""

from abc import ABCMeta, abstractmethod

import nltk
Expand Down
27 changes: 15 additions & 12 deletions src/textblob/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
.. versionchanged:: 0.8.0
These classes are now imported from ``textblob`` rather than ``text.blob``.
""" # noqa: E501

import json
import sys
from collections import defaultdict
Expand Down Expand Up @@ -65,7 +66,6 @@ def _penn_to_wordnet(tag):


class Word(str):

"""A simple word representation. Includes methods for inflection,
and WordNet integration.
"""
Expand Down Expand Up @@ -486,8 +486,14 @@ def pos_tags(self):
Example:
::

[('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'),
('Thursday', 'NNP'), ('morning', 'NN')]
[
("At", "IN"),
("eight", "CD"),
("o'clock", "JJ"),
("on", "IN"),
("Thursday", "NNP"),
("morning", "NN"),
]

:rtype: list of tuples
"""
Expand Down Expand Up @@ -775,15 +781,12 @@ def __repr__(self):
self.classifier.__class__.__name__ + "()" if self.classifier else "None"
)
return (
"Blobber(tokenizer={}(), pos_tagger={}(), "
"np_extractor={}(), analyzer={}(), parser={}(), classifier={})"
).format(
self.tokenizer.__class__.__name__,
self.pos_tagger.__class__.__name__,
self.np_extractor.__class__.__name__,
self.analyzer.__class__.__name__,
self.parser.__class__.__name__,
classifier_name,
f"Blobber(tokenizer={self.tokenizer.__class__.__name__}(), "
f"pos_tagger={self.pos_tagger.__class__.__name__}(), "
f"np_extractor={self.np_extractor.__class__.__name__}(), "
f"analyzer={self.analyzer.__class__.__name__}(), "
f"parser={self.parser.__class__.__name__}(), "
f"classifier={classifier_name})"
)

__str__ = __repr__
1 change: 1 addition & 0 deletions src/textblob/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

.. versionadded:: 0.6.0
""" # noqa: E501

from itertools import chain

import nltk
Expand Down
1 change: 1 addition & 0 deletions src/textblob/download_corpora.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$ python -m textblob.download_corpora lite

"""

import sys

import nltk
Expand Down
13 changes: 8 additions & 5 deletions src/textblob/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@

from textblob import formats


class PipeDelimitedFormat(formats.DelimitedFormat):
delimiter = '|'
delimiter = "|"


formats.register('psv', PipeDelimitedFormat)
formats.register("psv", PipeDelimitedFormat)

Once a format has been registered, classifiers will be able to read data files with
that format. ::

from textblob.classifiers import NaiveBayesAnalyzer

with open('training_data.psv', 'r') as fp:
cl = NaiveBayesAnalyzer(fp, format='psv')
with open("training_data.psv", "r") as fp:
cl = NaiveBayesAnalyzer(fp, format="psv")
"""

import csv
import json
from collections import OrderedDict
Expand Down Expand Up @@ -105,7 +108,7 @@ class JSON(BaseFormat):

[
{"text": "Today is a good day.", "label": "pos"},
{"text": "I hate this car.", "label": "neg"}
{"text": "I hate this car.", "label": "neg"},
]
"""

Expand Down
1 change: 1 addition & 0 deletions src/textblob/inflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

>>> from textblob.en.inflect import singularize
"""

from textblob.en.inflect import pluralize, singularize

__all__ = [
Expand Down
3 changes: 0 additions & 3 deletions src/textblob/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class ComparableMixin:

"""Implements rich operators for an object."""

def _compare(self, other, method):
Expand Down Expand Up @@ -33,7 +32,6 @@ def __ne__(self, other):


class BlobComparableMixin(ComparableMixin):

"""Allow blob objects to be comparable with both strings and blobs."""

def _compare(self, other, method):
Expand All @@ -44,7 +42,6 @@ def _compare(self, other, method):


class StringlikeMixin:

"""Make blob objects behave like Python strings.
Expects that classes that use this mixin to have a _strkey() method that
Expand Down
1 change: 1 addition & 0 deletions src/textblob/np_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
>>> from textblob.en.np_extractors import ConllExtractor
"""

from textblob.base import BaseNPExtractor
from textblob.en.np_extractors import ConllExtractor, FastNPExtractor

Expand Down
1 change: 1 addition & 0 deletions src/textblob/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
>>> from textblob.en.parsers import PatternParser
"""

from textblob.base import BaseParser
from textblob.en.parsers import PatternParser

Expand Down
1 change: 1 addition & 0 deletions src/textblob/sentiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

>>> from textblob.en.sentiments import PatternAnalyzer
"""

from textblob.base import BaseSentimentAnalyzer
from textblob.en.sentiments import (
CONTINUOUS,
Expand Down
1 change: 1 addition & 0 deletions src/textblob/taggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
>>> from textblob.en.taggers import NLTKTagger
"""

from textblob.base import BaseTagger
from textblob.en.taggers import NLTKTagger, PatternTagger

Expand Down
1 change: 1 addition & 0 deletions src/textblob/tokenizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.. versionadded:: 0.4.0
"""

from itertools import chain

import nltk
Expand Down
1 change: 1 addition & 0 deletions src/textblob/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.. versionadded:: 0.7.0
"""

import nltk

#: wordnet module from nltk
Expand Down
1 change: 1 addition & 0 deletions tests/test_blob.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for the text processor.
"""

import json
from datetime import datetime
from unittest import TestCase
Expand Down
5 changes: 1 addition & 4 deletions tests/test_classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@


class BadNLTKClassifier(NLTKClassifier):

"""An NLTK classifier without ``nltk_class`` defined. Oops!"""

pass
Expand Down Expand Up @@ -329,9 +328,7 @@ def test_accuracy(self):
def test_repr(self):
assert (
repr(self.classifier)
== "<PositiveNaiveBayesClassifier trained on {} labeled and {} unlabeled instances>".format( # noqa: E501
len(self.classifier.positive_set), len(self.classifier.unlabeled_set)
)
== f"<PositiveNaiveBayesClassifier trained on {len(self.classifier.positive_set)} labeled and {len(self.classifier.unlabeled_set)} unlabeled instances>" # noqa: E501
)


Expand Down